<?php
namespace app\index\controller;
use app\common\controller\HomeBase;



class Index extends  HomeBase
{


	
	public function _initialize()
	{
		parent::_initialize();
		
	}
	
   public function index(){

      	return $this->fetch();
   	
   }
   public function yzemailurl($id){
   	if (is_login()==0) {
   		 
   		$this->error('亲！请登录',es_url('index/login'));
   	} else {
   		$uid = is_login();
   		
   		
   		$user=self::$datalogic->setname('user')->getDataInfo(['id'=>$uid]);
   
   		if($id==md5($user['salt'].$uid.$user['usermail'])){
   			if($user['status']<3){
   				 
   				
   				self::$datalogic->setname('user')->setDataValue(['id'=>$uid],'status',2);
   			}else{
   				
   				self::$datalogic->setname('user')->setDataValue(['id'=>$uid],'status',5);
   			}

   			$this->success('验证成功',es_url('user/index'));
   			 
   			 
   		}else{
   			$this->error('非法验证',es_url('user/index'));
   		}
   
   	}
   	 
   	 
   	 
   	 
   }
   public function yzemail(){
   	 
   	$mail=$this->request->param();
   	
   	$uid =  is_login();
   	$user=self::$datalogic->setname('user')->getDataInfo(['id'=>$uid]);
   
   	$emailinfo=self::$datalogic->setname('user')->getDataInfo(['usermail'=>$mail['email'],'id|!'=>$uid]);
   	if($emailinfo){
   		$this->error('该邮箱已经被其他账号注册');
   	}else{
   		$n['usermail']=$mail['email'];
   		$where['id']=$uid;
   		self::$datalogic->setname('user')->dataEdit($n,$where,false);
   		
   	
   		$data['email']=$mail['email'];
   		$data['title']='邮箱验证';
   		$str=md5($user['salt'].$uid.$data['email']);
   		$data['body']='您的链接已经生成<br>http://'.$_SERVER['HTTP_HOST'].es_url('index/yzemailurl',array('id'=>$str));

   		
   		asyn_sendmail($data);
   		
   		$this->success('邮箱登录已更改为新邮箱，请到邮箱查收验证');
   		
   	}

   	 
   	 
   	 
   	 
   	 
   	 
   	 
   }
   public function forgetcodebymail(){
   	 
   	$mail=$this->request->param();
	 
   	$emailinfo=self::$datalogic->setname('user')->getDataInfo(['usermail'=>$mail['email']]);
   	//是否能得到
   	
   	
   	if($emailinfo){

   		 
   		$data['email']=$mail['email'];
   		$data['title']='忘记密码-邮箱验证';
 
   		 
   		$code=generate_code($mail['email']);
   		$data['body']='您的验证码已经生成<br>'.$code;
   		asyn_sendmail($data);
   		$this->success('验证码已经发送，请到邮箱查收验证');
   		
   		
   	}else{
   		$this->error('该邮箱不存在');
   	
  
   		 
   		 
   		 
   	}
   
   }
   public function reyzemail(){
   
   	$mail=$this->request->param();
   	$uid =  is_login();
   	$user=self::$datalogic->setname('user')->getDataInfo(['id'=>$uid]);
   	 
       
        $emailinfo=self::$datalogic->setname('user')->getDataInfo(['usermail'=>$mail['email'],'id|!'=>$uid]);
        echo 21;
        if($emailinfo){
        	dump($emailinfo);
        	$this->error('邮箱已被使用');
        }else{
        	$n['usermail']=$mail['email'];
        	if($user['status']==2){
        		$n['status']=1;
        	}else{
        		$n['status']=3;
        	}
        	$n['id']=$uid;
        	self::$datalogic->setname('user')->dataEdit('user',$n,false);
        	
        	 
        	$data['email']=$mail['email'];
        	$data['title']='邮箱验证';
        	$str=md5($user['salt'].$uid.$data['email']);
        	$data['body']='您的链接已经生成<br>http://'.$_SERVER['HTTP_HOST'].es_url('index/yzemailurl',array('id'=>$str));
        	asyn_sendmail($data);
        
        	$this->success('邮箱登录已更改为新邮箱，请到邮箱查收验证');
        	
        	
        	
        }

   }
   
   public function send_mail()
   {
   	 
   
   	$mail=$this->request->param();
   
   	$res=send_email($mail['email'], $mail['title'], $mail['body']);
   
   	if($res==1){
   		$this->success('邮件已发送，请到邮箱进行查收');
   	
   		//	$this->success('邮件已发送，请到邮箱进行查收');
   	}else{
   		$this->error('邮件发送失败，请检查邮箱设置');
   	
   		//$this->error('邮件发送失败，请检查邮箱设置');
   	}
   }
}
